//
//  HYGameInfoDetailScrollView.m
//  HaiYue
//
//  Created by skyline on 2018/5/16.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYGameInfoDetailScrollIMG.h"

@interface HYGameInfoDetailScrollIMG()


@end;
@implementation HYGameInfoDetailScrollIMG
- (instancetype)init
{
    self  = [super init];
    if (self)
    {
        self.backgroundColor = CELL_LINE_COLOR;
        self.showsHorizontalScrollIndicator = NO;
    }
    return self;
}

- (NSMutableArray *)itmes
{
    if (!_itmes)
    {
       _itmes = [NSMutableArray array];
    }
    return _itmes;
}

- (void)setImageNames:(NSArray *)imageNames
{
    if (_imageNames != imageNames)
    {
        _imageNames = imageNames;
        [self setupItems];
    }
}

- (void)setupItems
{
    CGFloat width = (SCREEN_WIDTH - 2 * GAP) / 3.0;
    self.contentSize = CGSizeMake((width + GAP) * _imageNames.count - GAP, 0);
    for (int i = 0; i < _imageNames.count; i++)
    {
       HYAutoIMG *item = [[HYAutoIMG alloc] initWithFrame:CGRectMake(0, 0, width, self.bounds.size.height)];
        item.tag = 200 + i;
        item.imageURL = _imageNames[i];
        [self.itmes insertObject:item atIndex:i];
        [item addTarget:self action:@selector(actionForScrollIMGItem:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:item];
        [item mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self);
            make.width.mas_offset(width);
            make.height.mas_offset(self.bounds.size.height);
            make.left.equalTo(self).with.offset((width + GAP) * i);
        }];
    }
}

- (void)actionForScrollIMGItem:(HYAutoIMG *)sender
{
    if (self.hydelegate && [self.hydelegate respondsToSelector:@selector(scrollItemSelectedIndex:)])
    {
        [self.hydelegate scrollItemSelectedIndex:(sender.tag - 200)];
    }
    DeLog(@"dianji     %ld",sender.tag);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
